<template>
  <!-- 归档任务管理 -->
  <div class="fileIntegrationSh">
    <!-- <div class="seach-content">
      <div class="demo-input-suffix">
        任务分类：
        <el-cascader v-model="value" :props="props"></el-cascader>
        <el-button type="primary" @click="search()"
          ><i class="el-icon-zoom-in el-icon--left"> 搜索</i></el-button
        >
        <el-button @click="reset()"
          ><i class="el-icon-refresh el-icon--left"> 重置</i></el-button
        >
      </div>
    </div> -->
    <div class="btn-continer">
      <!-- <el-button
        type="success"
        class="btn-lvse"
        @click="submit"
        style="margin-right: 10px"
        ><i class="el-icon-success el-icon--left"> 通过</i></el-button
      >

      <el-popconfirm confirm-button-text="好的" cancel-button-text="不用了">
      </el-popconfirm>
      <el-popover placement="right" width="400" trigger="click">
        <span>
          <el-input
            v-model="thval"
            placeholder="请输入退回意见"
            style="width: 75%; margin-right: 10px"
          ></el-input>
        </span>
        <span>
          <el-button type="primary" @click="goBack" class="btn-lanse">
            确定</el-button
          ></span
        >

        <el-button type="danger" slot="reference" class="btn-hongse"
          ><i class="el-icon-arrow-right el-icon--left"> 退回</i></el-button
        ></el-popover
      > -->
      <!-- <el-button><i class="el-icon-refresh el-icon--left"> 撤销</i></el-button> -->

      <div class="btn-right">
        <el-button
          style="margin-bottom: 10px"
          icon="el-icon-refresh-right"
          circle
          @click="refresh()"
        ></el-button>
      </div>
    </div>
    <div class="table-continer">
      <el-table
        :data="tableData"
        v-loading="loading"
        :highlight-current-row="true"
        :header-cell-style="{ background: '#F0F0F6', color: '#2D3548' }"
        row-key="id"
        style="width: 100%"
        @selection-change="selectionClick"
        ref="multipleTable"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column fixed label="文件名称">
          <template slot-scope="scope">
            {{ scope.row.fileInfo ? scope.row.fileInfo.fileName : "" }}
          </template>
        </el-table-column>
        <el-table-column label="编号">
          <template slot-scope="scope">
            {{ scope.row.fileInfo ? scope.row.fileInfo.id : "" }}
          </template>
        </el-table-column>
        <el-table-column label="文件大小">
          <template slot-scope="scope">
            {{ scope.row.fileInfo ? scope.row.fileInfo.fileSizeUnit : "" }}
          </template>
        </el-table-column>

        <el-table-column prop="fileType" label="文件类型">
          <template slot-scope="scope">
            <span v-if="scope.row.fileInfo.fileType == 1">图片</span>
            <span v-if="scope.row.fileInfo.fileType == 2">视频</span>
            <span v-if="scope.row.fileInfo.fileType == 3">文档</span>
            <span v-if="scope.row.fileInfo.fileType == 4">音频</span>
          </template>
        </el-table-column>
        <el-table-column prop="creator" label="创建人">
          <template slot-scope="scope">
            {{ scope.row.fileInfo ? scope.row.fileInfo.creator : "" }}
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间">
          <template slot-scope="scope">
            {{ scope.row.fileInfo ? scope.row.fileInfo.createTime : "" }}
          </template>
        </el-table-column>
        <!-- <el-table-column label="标签名称">
          <template slot-scope="scope">
            <el-tag
              class="pright"
              v-for="(item, index) in scope.row.fileInfo.fileLabel"
              :key="index + 'tag'"
              ><i :class="'el-icon--left xz'"></i
              >{{ item }}</el-tag
            >
          </template>
        </el-table-column> -->
        <el-table-column label="状态">
          <template slot-scope="scope">
            <span
              v-if="
                scope.row.fileInfo ? scope.row.fileInfo.fileStatus == 1 : false
              "
              >待提交</span
            >
            <span
              v-if="
                scope.row.fileInfo ? scope.row.fileInfo.fileStatus == 2 : false
              "
              >待审核</span
            >
            <span
              v-if="
                scope.row.fileInfo ? scope.row.fileInfo.fileStatus == 3 : false
              "
              >退回</span
            >
            <span
              v-if="
                scope.row.fileInfo ? scope.row.fileInfo.fileStatus == 4 : false
              "
              >审核通过</span
            >
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              @click="checkView(scope.row.fileInfo)"
              type="text"
              size="small"
              ><i class="el-icon-view el-icon--left"> 预览</i></el-button
            >
            <el-button
              @click="download(scope.row.fileInfo)"
              type="text"
              size="small"
              ><i class="el-icon-edit el-icon--left"> 下载</i></el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="Pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        :current-page="currentPage"
        :page-sizes="[5, 10, 15]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
      >
      </el-pagination>
    </div>
    <checkimg
      :imgList="imgList"
      :showViewer="showViewer"
      @closeImg="closeImg"
    />
    <openPdf ref="Pdf" />
    <openMusci
      :showPlayer="showPlayer"
      :videoPlay="videoPlay"
      @musicClose="musicClose"
    />
    <el-dialog
      title="视频"
      :visible.sync="playVideo"
      width="40%"
      @close="closeMp4"
    >
      <div class="content">
        <openMp4 :video="video" :playVideo="playVideo" />
      </div>
    </el-dialog>
  </div>
</template>

<script>
import checkimg from "../components/checkImg.vue";
import openPdf from "../components/openPdf.vue";
import openMp4 from "../components/openMp4.vue";
import openMusci from "../components/openMusci.vue";
export default {
  name: "fileIntegrationSh",
  components: { checkimg, openPdf, openMp4, openMusci },

  data() {
    return {
      currentPage: 1,
      loading: false,
      tableData: [],
      thval: "",
      pageSize: 10,
      totalSize: 0,
      selectId: [],
      showViewer: false,
      fileList: [],
      fileType: null, //文件类型
      imgList: [],
      showPlayer: false,
      playVideo: false,
      videoPlay: {
        title: "名称",
        artist: "音频",
        src: "",
        pic: "https://moeplayer.b0.upaiyun.com/aplayer/secretbase.jpg",
      },
      video: {
        // 视频播放源
        url: "",
        // 视频海报
        // cover: 'https://i.loli.net/2019/06/06/5cf8c5d9c57b510947.png',
        muted: false, // 是否静音播放
        loop: false, // 视频是否循环播放
        preload: "auto", // 视频预加载
        poster: "", // 原生视频默认海报暂不设置
        volume: 1, // 默认音量
        autoplay: false, // 视频自动播放
      },
      fileList: [
        {
          id: 1,
          fileName: "测试PDF",
          fileUrl: "http://192.168.3.189/aaa.pdf",
        },
      ],
      url: "http://192.168.3.189/aaa.pdf", //文件地址
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      let obj = {
        pageNum: this.currentPage,
        pageSize: this.pageSize,
        state: 0,
      };
      this.$api
        .TselectListTwo(obj)
        .then((res) => {
          if (res.code == 200) {
            res.data.list.forEach((s) => {
              if (s.fileInfo.fileLabel) {
                s.fileInfo.fileLabel = s.fileInfo.fileLabel.split(";");
              }
            });
            this.tableData = res.data.list;
            this.totalSize = res.data.total;
          } else {
            this.tableData = [];
            this.totalSize = 0;
          }
          this.loading = false;
          this.selectId = [];
        })
        .catch(() => {
          this.tableData = [];
          this.totalSize = 0;
          this.selectId = [];
          this.loading = false;
        });
    },

    submit() {
      this.selectId.forEach((res) => {
        delete res.tlabelInfo;
        delete res.fileInfo;
        delete res.fileLabelList;
        delete res.createTime;
        delete res.updateTime;
        res.auditOpinion = 0;
        res.businessType = 3;
      });
      if (this.selectId.length == 0) {
        this.$message({
          showClose: true,
          message: "请选择一条数据进行通过",
          type: "warning",
        });
        return;
      }

      this.$api.Tapproval(this.selectId).then((res) => {
        if (res.code == 200) {
          this.$message.closeAll();
          this.$message({
            showClose: true,
            message: res.msg,
            type: "success",
          });
          this.currentPage = 1;
          this.getList();
        }
      });
    },
    goBack() {
      this.selectId.forEach((res) => {
        delete res.tlabelInfo;
        delete res.fileInfo;
        delete res.fileLabelList;
        res.auditOpinion = 1;
        res.auditContent = this.thval;
        res.businessType = 3;
        delete res.createTime;
        delete res.updateTime;
      });
      if (this.selectId.length == 0) {
        this.$message({
          showClose: true,
          message: "请选择一条数据进行退回",
          type: "warning",
        });
        return;
      }
      // return false
      this.$api.Tapproval(this.selectId).then((res) => {
        if (res.code == 200) {
          this.$message.closeAll();
          this.$message({
            showClose: true,
            message: res.msg,
            type: "success",
          });
          this.currentPage = 1;
          this.getList();
        }
      });
    },
    selectionClick(row) {
      this.selectId = row;
    },
    refresh() {
      this.currentPage = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.pageSize = val;
      // console.log(`每页 ${val} 条`);
      this.getList();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      // console.log(`当前页: ${val}`);
      this.getList();
    },
    closeImg(flag) {
      this.showViewer = flag;
    },
    //下载
    download(row) {
      window.open(
        window.CONFIG.url + `/collect/projectReorganize/download/${row.id}`
      );
    },
    checkView(row) {
      this.$api
        .getUrl({ id: row.id })
        .then((res) => {
          if (res.data) {
            let type = row.fileType;
            console.log(type);
            if (type == 1) {
              this.imgList = [CONFIG.url + "/" + res.data];
              this.showViewer = true;
            } else if (type == 3) {
              this.$refs.Pdf.previewFn(CONFIG.url + "/" + res.data);
            } else if (type == 2) {
              this.video.url = CONFIG.url + "/" + res.data;
              this.$nextTick(() => {
                this.playVideo = true;
              });
            } else {
              this.showPlayer = false;
              let ipUrl = CONFIG.url + "/" + res.data;
              this.$nextTick(() => {
                this.videoPlay.src = ipUrl;
                this.videoPlay.title = "音频";
                this.videoPlay.artist = " ";
                this.showPlayer = true;
              });
            }
          } else {
            this.$message({
              showClose: true,
              message: res.msg,
              type: "error",
            });
          }
        })
        .catch((res) => {
          this.$message({
            showClose: true,
            message: res.msg,
            type: "error",
          });
        });
    },
    closeMp4() {
      this.$nextTick(() => {
        this.video.url = "obj";
        this.playVideo = false;
      });
    },
    musicClose(flag) {
      let ipUrl = "obj";
      this.$nextTick(() => {
        this.videoPlay.src = ipUrl;
        this.videoPlay.title = "";
        this.videoPlay.artist = "";
        this.showPlayer = flag;
      });
    },
  },
};
</script>
<style scoped lang="scss">
.fileIntegrationSh {
  padding: 0 30px;
  overflow: hidden;
  .seach-content {
    margin-top: 20px;
  }
  /deep/.el-button--primary {
    margin-left: 10px;
  }
  .content {
    height: 520px;
  }
  .pright {
    margin-right: 10px;
    margin-bottom: 10px;
  }
  .btn-continer {
    margin-top: 30px;
    margin-bottom: 20px;
    .btn-right {
      float: right;
    }
  }
  .Pagination {
    text-align: right;
    margin-top: 40px;
    margin-bottom: 40px;
  }
}
</style>

<style >
._progress ._time-current,
._progress ._time-amount {
  width: 80px;
}
</style>